//
//  oldActivityDetailHeaderView.m
//  laonianbang
//
//  Created by 勇拓 李 on 18/4/3.
//  Copyright © 2018年 zaiyou. All rights reserved.
//

#import "oldActivityDetailHeaderView.h"
#import "UIImageView+oldImageView.h"
#import "oldRatioImageView.h"

@interface oldActivityDetailHeaderView()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *label_introduction;
@property (weak, nonatomic) IBOutlet UILabel *label_price;
@property (weak, nonatomic) IBOutlet UILabel *label_time;
@property (weak, nonatomic) IBOutlet UILabel *label_address;
@property (weak, nonatomic) IBOutlet UILabel *label_organization;
@property (weak, nonatomic) IBOutlet UILabel *label_mobile;
@property (weak, nonatomic) IBOutlet UILabel *label_number;
@property (weak, nonatomic) IBOutlet UILabel *label_joinEnd;
@property (nonatomic, strong)UIPageControl *pageControl;
@property (weak, nonatomic) IBOutlet UIView *baseView;
@end

@implementation oldActivityDetailHeaderView

- (void)awakeFromNib
{
    [super awakeFromNib];
    _baseView.layer.cornerRadius = 6.f;
    _baseView.layer.shadowColor = [UIColor blackColor].CGColor;
    _baseView.layer.shadowOpacity = 0.5f;
    _baseView.layer.shadowOffset = CGSizeMake(2, 2);
    _baseView.layer.shadowRadius = 5;
}

- (void)setActivity:(oldActivity *)activity
{
    _activity = activity;
    [self initScrollView];
    _label_time.text = [NSString stringWithFormat:@"%@至%@", activity.startTime, activity.endTime];
    _label_price.text = [activity getFeeByPeople];
    _label_mobile.text = activity.phone;
    _label_address.text = activity.address;
    _label_organization.text = activity.owner;
    _label_introduction.text = activity.content;
    _label_number.text = [NSString stringWithFormat:@"%@人", activity.joinCount];
    
    _label_joinEnd.text = activity.joinEndTime;
}

#pragma mark - 返回高度
- (CGFloat)getHeight:(oldActivity *)activity
{
    UILabel *label = [[UILabel alloc] init];
    [label setFont:[UIFont systemFontOfSize:12.f]];
    
    label.text = activity.content;
    
    CGSize s_label = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH - 80 , FLT_MAX)];
    
    CGFloat height = (s_label.height + 617);
    
    return height;
}

#pragma mark - 设置相册图片
- (void)initScrollView
{
    NSArray *array = [_activity getPicArray];
    
    _scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * ([array count]), 0);
    _scrollView.delegate = self;
    _scrollView.pagingEnabled = YES;
    _scrollView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    _scrollView.layer.borderWidth = 0.5f;
    [_scrollView setShowsVerticalScrollIndicator:NO];
    [_scrollView setShowsHorizontalScrollIndicator:NO];
    _scrollView.backgroundColor = Color_With_Rgb(242, 242, 242, 1);
    
    for (int i = 0; i < [array count]; i++) {
        oldRatioImageView *imageView = [[oldRatioImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width * i, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width)];
        imageView.tag = i;
        NSString *imageStr = array[i];
        [imageView showImage:imageStr];
        [_scrollView addSubview:imageView];
    }
    
    if ([array count]) {
        _pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, SCREEN_WIDTH - 10, self.frame.size.width, 40)];
        [_pageControl setCurrentPage:0];
        _pageControl.numberOfPages = [array count] + 1;//指定页面个数
        [_pageControl setBackgroundColor:[UIColor clearColor]];
        _pageControl.userInteractionEnabled = NO;
        [_scrollView.superview addSubview:_pageControl];
    }
}

@end
